import { service as request } from '@/utils/request'

/**
 * 获得部门列表
 * 接口10.9
 * 
 * @param {*} data 
 * @returns 
 */
export function getList (data) {
  return request({
    url: `/hawk/department/search/${data.page.current}/${data.page.size}`,
    method: 'get',
    params: data.query
    // params: {
    //   name: data.query.name,
    //   companyId: data.query.companyId
    // }
  })
}



/**
 * 分页查询公司
 * @param {*} data 
 * @returns 
 */
 export function isNameHave (companyId,name) {
  return request({
    url: `/hawk/department/exists`,
    method: 'get',
    params: {
      name: name,
      companyId:companyId
    }
  })
}



/**
 * 新建部门
 * @param {*} data 
 * @returns 
 */
export function doAdd (data) {
  return request({
    url: '/hawk/department/save',
    method: 'post',
    data: {
      companyId: data.companyId,
      name: data.name
    }
  })
}
/**
 * 
 * @param {*} data 
 * @returns 
 */
export function doEdit (data) {
  return request({
    url: '/hawk/department/update',
    method: 'put',
    data: {
      companyId: data.company.id,
      id: data.id,
      name: data.name
    }
  })
}
/**
 * 
 * @param {*} id 
 * @returns 
 */
export function doDelete (ids) {
  return request({
    url: `/hawk/department/del`,
    method: 'delete',
    data: ids
  })
}


// 根据 ID 查部门
export function getOne (id) {
  return request({
    url: `/hawk/department/get/${id}`,
    method: 'get'
  })
}



export function getAll () {
  return request({
    url: `/hawk/assets/dictionaries/department`,
    // url: `/hawk/company/get/department/all`,
    method: 'get'
  })
}
export function getAllDept(){
  return request({
    url: `/hawk/department/get/all`,
    // url: `/hawk/company/get/department/all`,
    method: 'get'
  })
}

/**
 * 根据公司 ID 获得所有部门
 * @param {*} comId 
 * @returns 
 */
export function getDepartByComId (comId) {
  return request({
    url: `/hawk/department/get/company/${comId}`,
    method: 'get'
  })
}
